/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.zr.coverflow.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;

import java.util.ArrayList;

import me.crosswall.coverflow.demo.ResourceTable;
import me.crosswall.lib.coverflow.PageSliderAdapter;
import me.crosswall.lib.coverflow.view.PagerContainer;

/**
 * DefaultScrolledViewProvider
 *
 * @since 2021-03-26
 */
public class ColorViewpage extends AbilitySlice {
    private PagerContainer colorPageSlider;
    private Text colortext;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_colorviewpage_layout);
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(ResourceTable.Media_color_0);
        arrayList.add(ResourceTable.Media_harcolor1);
        arrayList.add(ResourceTable.Media_harcolor2);
        arrayList.add(ResourceTable.Media_harcolor3);
        arrayList.add(ResourceTable.Media_harcolor4);
        arrayList.add(ResourceTable.Media_harcolor5);
        arrayList.add(ResourceTable.Media_harcolor6);
        arrayList.add(ResourceTable.Media_harcolor7);
        arrayList.add(ResourceTable.Media_harcolor8);
        arrayList.add(ResourceTable.Media_harcolor9);
        arrayList.add(ResourceTable.Media_harcolor10);
        arrayList.add(ResourceTable.Media_harcolor11);
        arrayList.add(ResourceTable.Media_harcolor12);
        arrayList.add(ResourceTable.Media_harcolor13);
        arrayList.add(ResourceTable.Media_harcolor14);
        colortext = (Text) findComponentById(ResourceTable.Id_Colortext);
        colorPageSlider = (PagerContainer) findComponentById(ResourceTable.Id_ColorPageSlider);
        PageSliderAdapter bannerAdapter = new PageSliderAdapter(arrayList, this);
        colorPageSlider.setPageadapter(bannerAdapter);
        colorPageSlider.setCurrpage(0);
        PagerContainer.PageItemClickListener onSelectListener = new PagerContainer.PageItemClickListener() {
            @Override
            public void onItemClick(int index) {
                colortext.setText("Item " + index);
            }

            @Override
            public void onPageSliding(int i2, float v1, int i1) {
            }
        };
        colorPageSlider.setPageItemClickListener(onSelectListener);
    }
}
